Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <script src="../../ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("body").on("click","p",function(){ $(this).css("background-color","pink"); }); $("#btn1").click(function(){ $("body").off("click","p"); }); $("#btn2").click(function(){ $("body").undelegate("p","click"); }); }); </script> </head> <body> <h4 style="color:green;">This example demonstrates how to achieve the same effect using off() and undelegate().</h4> <p>Click this paragraph to change its background color.</p> <p>Click the button below and then click on this paragraph (the click event is removed).</p> <button id="btn1">Remove the click event with off()</button> <button id="btn2">Remove the click event with undelegate()</button> </body> <!-- Mirrored from www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_off_undelegate by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:14:48 GMT --> </html>
Result:
Try it Yourself - © w3schools.com